<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Hook
 *
 * @author ngh
 */
class Hook {
    
    private $registry;
    
    public function __construct() {
        $this->registry = $this->registry = Registry::getInstance();
    }


    public function invoke($subject_name, $hook_name, &$args=array())
    {
        $module = $this->registry->modules[$subject_name];
        foreach ($module['hooks'] as $class => $hookarray) {
                foreach($hookarray as $hookfunction)
                    if('hook_' . $hook_name == $hookfunction)
                    {
                        $obj = new $class();
                        $obj->$hookfunction($args);
                    }
            }
    }
    
    public function invokeAll($hook_name, &$args=array())
    {
        foreach ($this->registry->modules as $module_name => $module) {
            foreach ($module['hooks'] as $class => $hookarray) {
                foreach($hookarray as $hookfunction)
                    if('hook_' . $hook_name == $hookfunction)
                    {
                        $obj = new $class();
                        $obj->$hookfunction($args);
                    }
            }
        }
        
    }
}

?>
